﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace TimHeuer.WindowsLiveWriter.S34Writer
{
    public partial class KeyPrompt : Form
    {
        private string _filePath = String.Empty;
        private string _key = String.Empty;

        public KeyPrompt()
        {
            InitializeComponent();
        }

        public string FilePath
        {
            get { return _filePath; }
            set
            {
                _filePath = value;
                if (!String.IsNullOrEmpty(_filePath))
                {
                    FileName = Path.GetFileName(_filePath);
                    toolTip.SetToolTip(FileNameLabel, _filePath);

                    // Initialize the key name to the file name,
                    // with underscores for spaces.
                    KeyNameTextBox.Text = Utilities.GetKeyFromFileName(FileName);
                }
            }
        }

        private string FileName
        {
            get { return FileNameLabel.Text.Trim(); }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    FileNameLabel.Text = value.Trim();
                }
                else
                {
                    // This would be considered an error condition!
                    FileNameLabel.Text = "<none specified>";
                }
            }
        }

        public string Key
        {
            get { return KeyNameTextBox.Text.Trim(); }
        }

        public bool AutoUploadFileName
        {
            get { return AutoUploadCheckBox.Checked; }
        }

        public bool OverrideContentType
        {
            get { return OverrideCtCheckbox.Checked; }
        }

        public string ContentType
        {
            get { return CustomContentType.Text; }
        }

        private void KeyNameTextBox_TextChanged(object sender, EventArgs e)
        {
            // Enable the OK button if we have text entered, and it doesn't contain a space.
            string key = KeyNameTextBox.Text.Trim();
            OKButton.Enabled = !String.IsNullOrEmpty(key) && !key.Contains(" ");
        }

        private void OverrideCtCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            CustomContentType.Enabled = OverrideCtCheckbox.Checked;
        }
    }
}
